package controlSoftware.MockDataIn;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import controlSoftware.DataProcess.SensorData;
import controlSoftware.DataProcess.SysModel;

public class MockDataSource {
	int t = 0;
	SensorData data = null;

	Queue<SensorData> mockData = new ConcurrentLinkedQueue<SensorData>();

	public MockDataSource(String filePath) {
			try {
				FileInputStream fstream = new FileInputStream(filePath);
				InputStreamReader dataIn = new InputStreamReader(fstream);
				BufferedReader reader = new BufferedReader(dataIn);

				String[] data;
				String line;
				
				while ((line = reader.readLine()) != null) {
					Thread.sleep(SysModel.sampleTime);
					
					data = line.split("\\,");
					SensorData dataObj = new SensorData(
							Long.parseLong(data[0]),
							Double.parseDouble(data[1]),
							Double.parseDouble(data[2]), 
							Double.parseDouble(data[3]), 
							Double.parseDouble(data[4]), 
							Double.parseDouble(data[5]),
							Double.parseDouble(data[6]));
					
					mockData.add(dataObj);
				}
			} catch (Exception e) {
				System.out.println("File: "+ filePath + "\n" + e.getMessage());
			}
	}

	public SensorData getNextMockData() {
		return mockData.poll();
	}

}
